


def elapsed_str(val):
    unit_map = [
        (1, 's'),
        (0.001, 'ms'),
        (0.000001, 'us'),
        (0.000000001, 'ns')
    ]
    for threshold, unit in unit_map:
        if val >= threshold:
            return f"{val / threshold:.2f}{unit}"
    return f"0.00 ns"
    
def freq_str(f):
    unit_map = [
        (1e9, 'GHz'),
        (1e6, 'MHz'),
        (1e3, 'KHz'),
        (1, 'Hz')
    ]
    for threshold, unit in unit_map:
        if f >= threshold:
            return f"{f / threshold:.2f}{unit}"
    return f"0.00Hz"

def distance_str(d):
    unit_map = [
        (1e3, 'km'),
        (1, 'm')
    ]
    for threshold, unit in unit_map:
        if d >= threshold:
            return f"{d / threshold:.2f}{unit}"
    return f"0.00m"